package br.usjt.component.login.beans;

import static javax.ejb.ConcurrencyManagementType.CONTAINER;
import static javax.ejb.LockType.READ;
import static javax.ejb.LockType.WRITE;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.annotation.PostConstruct;
import javax.ejb.ConcurrencyManagement;
import javax.ejb.Lock;
import javax.ejb.Singleton;
import javax.ejb.Startup;

import br.usjt.component.login.model.Login;

@Singleton
@Startup
@ConcurrencyManagement(CONTAINER)
public class LoginSingletonBean implements Serializable {

    private static final long serialVersionUID = 541971222558338136L;

    private Set<Login> logins;

    @PostConstruct
    void startup() {
        logins = new HashSet<Login>();
    }

    @Lock(WRITE)
    public void addLogins(Login login) {
        logins.add(login);
    }

    public void removeLogins(Login login) {
        logins.remove(login);
    }

    @Lock(READ)
    public boolean constainLogin(Login login) {
        return logins.contains(login);
    }

}
